package com.tf.six.controller;




import com.tf.six.entity.Comment;
import com.tf.six.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
@Tag(name = "评价管理", description = "处理商品评价相关操作")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping
    @Operation(summary = "添加评价")
    public boolean addComment(@RequestBody Comment comment) {
        return commentService.save(comment);
    }

    @GetMapping("/product/{productId}")
    @Operation(summary = "获取商品评价")
    public List<Comment> getCommentsByProduct(@PathVariable Long productId) {
        return commentService.lambdaQuery()
                .eq(Comment::getProductId, productId)
                .list();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除评价")
    public boolean deleteComment(@PathVariable Long id) {
        return commentService.removeById(id);
    }
}